#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+5;
ll d[maxn][maxn];
int l[maxn], w[maxn], u[maxn], n, x;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) {
        cin >> l[i] >> w[i] >> u[i];
        for (int j = x; j >=0 ; --j) {
            d[i][j] = d[i-1][j] + l[i];
            if(j>=u[i]) d[i][j] = max(d[i][j], d[i-1][j-u[i]] + w[i]);
        }
    }
    cout << 5*d[n][x];
    return 0;
}